var $;
var table;
var layer;
var form;
layui.use(['table','element','layer'],function() {
    dtree = layui.dtree;
    $ = layui.jquery;
    table = layui.table;
    layer = layui.layer;
    form = layui.form;
    setComment('','','');

    //页面刷新
    $("#btn_1").on('click',function(){
        location.reload(true);
    })
    function setComment(beid,name,content){
        $.ajax({
            url:"/SyteacherSelController/setComment",
            type:"post",
            dataType:"json",
            data:{"beforeId":beid,"beforeName":name,"content":content},
            success:function(data){
                TabView(data.data);
            }
        })
    }
    //模糊查询
    $("#btn_2").on('click',function(){
        //用户账号
        var beforeid=$("#userId").val();
        //用户昵称
        var beforeName=$("#accId").val();
        //评论关键字
        var content=$("#actId").val();

        setComment(beforeid,beforeName,content);
    })

    function TabView(da){
        table.render({
            elem:"#tab_id",
            data:da,
            height:250,
            limit:3,
            toolbar:'#toolbarDemo',
            page:{
                layout:['count','prev','page','next','limit','skip','refresh'],
                limits:[3,6,9],
                first:"首页",
                last:"尾页",
            },
            cols:[[
                {type:'radio',fixed:'left',width:60},
                {title:'序号',templet:function(data){
                        return data.LAY_INDEX;
                    }},
                {field:'userName',title:'用户'},
                {field:'courseName',title:'课程名称'},
                {field:'content',title:'评价'},
                {field:'commentDate',title:'评论时间'},
                {field:'account',title:'用户账号'},

                {field:'details',title:"操作",width:120,templet:function(data){
                        return "<a href='#' onclick='javascript:selectCourseTable("+data.courseid+","+data.id+")' style='color: #1ABC9C'>查看</a>&nbsp<a href='#' onclick='javascript:delectCommentTable("+data.id+")' style='color: #1ABC9C'>删除</a>"
                    }}

            ]]
        });
    }
})

function delectCommentTable(id){
    $.ajax({

        url:"/SyteacherSelController/DeCommentTab",
        type:"post",
        dataType:"json",
        data:{"commentid":id},
        success:function(data){
        }
    })
}
//课程详情
function selectCourseTable(courseid,id){
    layer.open({
        type:2,
        title:"课程详情",
        area:['1000px','550px'],
        shade:0.4,
        offset:'auto',
        content:"CommentDetails.html",
        success:function(layero,index){
            var obj = layero.find('iframe').contents();
            obj.find('input[name=forumId]').val(courseid);
            obj.find('input[name=commentid]').val(id);
        }
    })
}

